const designDao = require('../dao/design');
const util = require('../utilitys');
/**
 * 获取文件夹列表
 * @param ctx
 * @returns {Promise<boolean>}
 * @constructor
 */
exports.typeListDesign = async (ctx) => {
    try {
        let result = await designDao.typeListDesign(ctx);
        if (result.length > 0) {
            ctx.body = util.resultSuccessJson(undefined, undefined, result);
        } else {
            ctx.body = util.resultSuccessJson(undefined, '请求错误', {});
        }
    } catch (err) {
        ctx.body = util.resultErrorJson(undefined, err, {});
    }
};

/**
 * 记录下载量和浏览量
 * @param ctx
 * @returns {Promise<boolean>}
 * @constructor
 */
exports.record = async (ctx) => {
    try {
        let result = await designDao.record(ctx);
        if (result.length > 0) {
            ctx.body = util.resultSuccessJson(undefined, undefined, result);
        } else {
            ctx.body = util.resultSuccessJson(undefined, '请求错误', {});
        }
    } catch (err) {
        ctx.body = util.resultErrorJson(undefined, err, {});
    }
};

/**
 * 获取文件列表
 * @param ctx
 * @returns {Promise<boolean>}
 * @constructor
 */
exports.getFileList = async (ctx) => {
    try {
        let result = await designDao.getFileList(ctx);
        if (result.length > 0) {
            ctx.body = util.resultSuccessJson(undefined, undefined, result);
        } else {
            ctx.body = util.resultSuccessJson(undefined, undefined, result);
        }
    } catch (err) {
        ctx.body = util.resultErrorJson(undefined, err, {});
    }
};

/**
 * 获取下载量
 * @param ctx
 * @returns {Promise<boolean>}
 * @constructor
 */
exports.getDownloadCount = async (ctx) => {
    try {
        let result = await designDao.getDownloadCount(ctx);
        if (result.length > 0) {
            ctx.body = util.resultSuccessJson(undefined, undefined, result);
        } else {
            ctx.body = util.resultSuccessJson(undefined, undefined, result);
        }
    } catch (err) {
        ctx.body = util.resultErrorJson(undefined, err, {});
    }
};
